package com.hehe.httpurlconnectiontest2;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import java.util.LinkedList;

/**
 * Created by lenove on 2017/11/11.
 *
 * 传感器分页面
 */

public class SensorsFragment extends Fragment {

    LinkedList<YeelinkDecives> data;
    SensorBaseAdapter sensorBaseAdapter;
    int DevicePosition;

    SensorsFragment(LinkedList<YeelinkDecives> data,int DevicePosition){
        this.data = data;
        this.DevicePosition = DevicePosition;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.layout_fragment,container,false);
        //TODO 之后再写BaseAdapter
        ListView mySensorsListView = (ListView)view.findViewById(R.id.ListViewInFragment);
        sensorBaseAdapter = new SensorBaseAdapter(data,getActivity(),DevicePosition);
        mySensorsListView.setAdapter(sensorBaseAdapter);
        return view;
    }

    public void flash(){
        sensorBaseAdapter.notifyDataSetChanged();
    }

//    public void addSensor(YeelinkSensor yeelinkSensor){
//        if (sensorBaseAdapter!=null){
//            sensorBaseAdapter.addSensor(yeelinkSensor);
//        }
//    }

//    public void setDataList(LinkedList<YeelinkSensor> data) {
//        sensorBaseAdapter.setDataList(data);
//    }
}
